package conservare.modelo.local;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import conservare.modelo.CpfCnpj;
import conservare.modelo.Endereco;
import conservare.modelo.Pessoa;

@Entity
@Table(name="TB_LOCAL_PS")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="DISCRIMINATOR_COLUMN", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("LOCAL_PRESTACAO_SERVICO")
public abstract class LocalPrestacaoServico implements Serializable{

	private static final long serialVersionUID = 3787202075363226836L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="LOCAL_PS_ID")
	protected Integer id;

	protected CpfCnpj cpfCnpj;
	
	@Column(name="descricao")
	protected String nome;
	
	@ManyToOne
	@JoinColumn(name="RESPONSAVEL_ID")
	protected Pessoa responsavel;
	
	@Embedded
	protected Endereco endereco;
	
	
	public abstract String getDescricaoTipoLocal();
	
	
	public void adicionarResponsavelPeloLocalPrestacaoServico(Pessoa responsavel){
		this.responsavel = responsavel;
	}
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String descricao) {
		this.nome = descricao;
	}

	public Endereco getEndereco() {
		return endereco;
	}

	public void setEndereco(Endereco endereco) {
		this.endereco = endereco;
	}
	
	public Pessoa getResponsavel() {
		return responsavel;
	}

	public CpfCnpj getCpfCnpj() {
		return cpfCnpj;
	}

	public void setCpfCnpj(CpfCnpj cpfCnpj) {
		this.cpfCnpj = cpfCnpj;
	}

	public String getCpfCnpjFormatado(){
		return getCpfCnpj() != null ? getCpfCnpj().getCpfCnpjFormatado() : " ";
	}
	
	public String getEnderecoCompletoFormatadoParaUmaLinha(){
		return getEndereco().getEnderecoCompletoFormatadoParaUmaLinha();
	}
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		LocalPrestacaoServico other = (LocalPrestacaoServico) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
